<?php
namespace Home\Controller;
use Think\Controller;
class TempQuizController extends Controller {

    public function index($quiz_key)
    {
        $tempquiz_list = D('tempquiz_list');
        $keyinfo = $tempquiz_list->where(['quiz_key' => $quiz_key])->select();
        if (!$keyinfo){
            header("Content-type: text/html; charset=utf-8");
            echo "序列号无效！";
            return;
        }

        else{

            $quiz_info['quiz_useremail'] = $keyinfo[0]['quiz_useremail'];
            $quiz_info['quiz_username'] = $keyinfo[0]['quiz_username'];
            $quiz_info['quiz_usersex'] = $keyinfo[0]['quiz_usersex'];

            $this->assign('quiz_info', $quiz_info);

            if(IS_AJAX){

                $data['quiz_usersex'] = I('quiz_usersex');
                $data['quiz_useremail']= I('quiz_useremail');
                $data['quiz_username'] = I('quiz_username');


                $status = $tempquiz_list->where(['quiz_id' =>  $keyinfo[0]['quiz_id']])->save($data);
                if(!$status){
                    $rs['code'] = -1;
                    $rs['msg'] = $tempquiz_list->getError();
                    $this->ajaxReturn($rs);

                }
                else{
                    $rs['code'] = 1;
                    $rs['msg'] = '成功提交测试者信息，开始测试';
                    $this->ajaxReturn($rs);
                }

                if (!$data = $tempquiz_list->create()) {
                    // 防止输出中文乱码
                    header("Content-type: text/html; charset=utf-8");
                    $rs['code'] = -1;
                    $rs['msg'] = $tempquiz_list->getError();
                    $this->ajaxReturn($rs);
                    return;
                }
            }
            else{
                $this->assign('quiz_key', $quiz_key);
                $this->display();
            }
        }






    }


}